package GUI;

import Model.Supplier;

import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

public class SupplierTableModel extends DefaultTableModel {

        private ArrayList<Supplier> data;

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

        public void setData(ArrayList<Supplier> data)
        {
            this.data = data;
            fireTableDataChanged();
        }

        public ArrayList<Supplier> getData() {
            return data;
        }

        @Override
        public int getColumnCount() {
            return 6;
        }

        @Override
        public int getRowCount()
        {
            if(data == null)
            {
                return 0;
            }
            else
            {
                return data.size();
            }
        }

        @Override
        public String getColumnName(int column) {
            String columnName = "";
            switch(column)
            {
                case 0:
                    columnName = "ID";
                    break;
                case 1:
                    columnName = "Name";
                    break;
                case 2:
                    columnName = "Address";
                    break;
                case 3:
                    columnName = "Country";
                    break;
                case 4:
                    columnName = "Phone No";
                    break;
                case 5:
                    columnName = "Email";
                    break;
            }
            return columnName;
        }


        @Override
        public Object getValueAt(int row, int column)
        {
            Object value = null;
            switch(column)
            {
                case 0:
                    value = data.get(row).getId();
                    break;
                case 1:
                    value = data.get(row).getName();
                    break;
                case 2:
                    value = data.get(row).getAddress();
                    break;
                case 3:
                    value = data.get(row).getCountry();
                    break;
                case 4:
                    value = data.get(row).getPhoneNo();
                    break;
                case 5:
                    value = data.get(row).getEmail();
            }

            return value;
        }
}
